package com.paradogs.gs.modules.friend;

import com.paradogs.framework.annotations.serverHandler.PRHandler;
import com.paradogs.framework.annotations.serverHandler.PRMapping;
import com.paradogs.framework.misc.GC;
import com.paradogs.gs.misc.Bow;
import com.paradogs.gs.misc.fastWrap.LongWrapper;
import com.paradogs.gs.modules.Player;
import com.paradogs.gs.utils.PlayerUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * @author: yumi
 * @date: 2024/12/23  14:55
 * @Description: TODO
 */
@Slf4j
@PRHandler
@PRMapping("friend")
public class FriendHandler {

    /** 申请好友 */
    @PRMapping("apply")
    public GC apply(LongWrapper targetId) {
        Bow.asserts(targetId != null, "找不到玩家");
        Player target = PlayerUtils.getPlayer(targetId.getVal());
        Bow.asserts(target != null, "玩家不在线");
        Bow.asserts(!Bow.owner().friendMgr().hasFriend(targetId.getVal()), "已经是好友了");

        if (target.friendApplyMgr().__raw__().values().stream()
                .anyMatch(apply -> apply.getApplyUid().equals(Bow.owner().getId()))) {
            target.friendApplyMgr().tryAddOneApply(
                    Bow.owner().getId(),
                    Bow.owner().roleMgr().__raw__().getNickName()
            );
        }

        return GC.ok();
    }

    /** 同意申请 */
    @PRMapping("agree")
    public GC agree(LongWrapper applyId) {
        Bow.asserts(applyId != null
                && Bow.owner().friendApplyMgr().get(applyId.getVal()) != null, "申请不存在");
        Bow.owner().friendApplyMgr().agree(applyId.getVal());
        return GC.ok();
    }

    /** 拒绝申请 */
    @PRMapping("refuse")
    public GC refuse(LongWrapper cg) {
        return GC.ok();
    }

}
